package intermouse;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Console;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

import javax.swing.JOptionPane;

/**
 * A program működését indító osztály.
 * 
 * @author Demény Fruzsina Gyöngyi, Sőre András
 * @version 1.0
 * @since 2013-03-23
 */
public class Main extends Thread{

	static boolean gameRunning = true;
	

	private static int sleepMs = 200;

	
	/**
	 * @param args
	 * @throws InterruptedException 
	 * 
	 */
	
	public static void main(String[] args) {
		gameRunning = true;
		GraphicsManager.getInstance().pack();
		
		Level.getInstance().init();
		GraphicsManager.getInstance().updateWidget();
		
		while(gameRunning){
			try {
				sleep(sleepMs);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			GameState.getInstance().setplayerScore(GameState.getInstance().getPlayerScore()+1);
			GraphicsManager.getInstance().updateWidget();
			Level.getInstance().makeStep();
		}
		
	}
	
	public static void gameOver()
	{
		gameRunning = false;
		JOptionPane.showMessageDialog(GraphicsManager.getInstance().getContentPane(), "játék vége! pontszám: " +
		GameState.getInstance().getPlayerScore(), "Játék vége!", JOptionPane.INFORMATION_MESSAGE);
		reset();
	}
	
	public static boolean isGameOver()
	{
		return !gameRunning;
	}
	
	static void reset(){
		gameRunning = true;
		Level.reset();
		Level.getInstance().init();
		GameState.reset();
		GraphicsManager.getInstance().updateWidget();
	}
	
}
